package middlewares

import (
	"github.com/labstack/echo/v4"
	"longmen/server/config/global"
	"longmen/server/pkg/common/api_models"
)

func CheckMaintain() echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			//if !cache.IpCallAvailable(c.RealIP(), "") {
			//	return utils2.BuildLoginTimeOut(c, errors.New("超过流量限制！！！！！！"))
			//}
			if r, _ := global.GetRds().Get("CHECK_MAINTAIN").Result(); r == "1" {
				return c.JSON(503, api_models.Response{
					Status: 1,
					Msg:    "平台维护中",
					ErrMsg: "平台维护中",
				})
			}
			return next(c)
		}
	}
}
